class Population
	attr_accessor :selectors
	attr_accessor :operators
	attr_accessor :subjects
	attr_accessor :chromosome_sample

	def initialize
		@selectors = []
		@operators = []
		@subjects = []
		@chromosome_sample = nil
	end

	def create_population(number)
		GenRepository.instance.chromosome_sample = @chromosome_sample
		number.times{@subjects << GenRepository.instance.get_chromosome}
		@subjects.each{|subject| subject.evaluate}
	end
	
	def evolve(number)
		number.times{evolve_once}
	end

	def size
		@subjects.size
	end

	def evolve_once
		@selectors.each{|selector| @subjects = selector.select(@subjects)}
		@operators.each{|operator| @subjects = operator.operate(@subjects)}
		@subjects.each{|subject| subject.evaluate}
	end

	def get_fittess(ntop)
		@subjects.sort{|sub1,sub2|sub1.fitness_value <=> sub2.fitness_value}.reverse.take(ntop)
	end
end
